home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / basic / qbfaqr01.zip / MBF2NUM.QRM < prev    next >
Text File  |  1992-07-31  |  2KB  |  73 lines

  1.  
  2. ─ Area: R-QBasic ─────────────────────────────────────────────────────────────
  3.   Msg#: 13834                                        Date: 07-30-92  03:33
  4.   From: Nick Dyer                                    Read: Yes    Replied: No 
  5.     To: Robert Laszko                                Mark:                     
  6.   Subj: Numeric conversion help
  7. ──────────────────────────────────────────────────────────────────────────────
  8.  
  9. RL>
  10. RL>I'm writing a routine to display the number of active records in a
  11. RL>given PCBoard message base file. According to PCBoard's file format
  12. RL>this number is contained in bytes 8 through 11, stored as a Basic S
  13. RL>Precision Real Number. Problem is .... I don't know how to convert 
  14. RL>these four bytes into a usable, decimal equivalant.
  15.  
  16. I think you will find that the following will help if you use Basic
  17.  
  18. If the 4 byte Basic Real is stored in a string say A$ then,
  19.  
  20.  Q&=CVSMBF(A$)
  21.  
  22. will place in variable Q& the converted value.
  23.  
  24. RL> 
  25. RL>So what now, coach?? ..... What I'm NOT looking for is the name of 
  26. RL>C or Pascal function to do the conversion (but if that's all you ha
  27. RL>I'll take it :) ). I'm using a higher-level language to manipulate
  28.  
  29. Michael Stewart showed me this technique:
  30.  
  31. Sub MsFloatToLong (MsFloat As String, L1 As Long)
  32.  
  33.     I1& = Asc(Mid$(MsFloat$, 1))
  34.     I2& = Asc(Mid$(MsFloat$, 2))
  35.     I3& = Asc(Mid$(MsFloat$, 3))
  36.     I4& = Asc(Mid$(MsFloat$, 4))
  37.  
  38.     
  39.     L1& = ((I1& + (I2& * 256) + (I3& * 65536)) Or &H800000) / (2 ^ (24 -
  40. (I4& - &H80)))
  41.     
  42.      
  43. End Sub
  44.  
  45. Calling the above sub passing the variables containing the four byte basic
  46. real string and a receiving long integer variable will carry out the
  47. conversion necessary.
  48.  
  49. An unsung hero did this in C, (Author Unknown)
  50.  
  51. Unsigned long mbf_to_int (m1,m2,m3,exp)
  52.  
  53. unsigned int m1,m2,m3,exp;
  54.  
  55. {
  56.  return (((m1 + ((unsigned long) m2 << 8) + ((unsigned long) m3 <<
  57.              16)) | 0x800000L) >> (24 - (exp - 0x80)));
  58. }
  59.  
  60.  
  61. I hope all this helps you. Good Luck!!
  62.  
  63.  
  64. Regards
  65. Nick Dyer                                 nick.dyer@almac.co.uk
  66.  
  67. -!-
  68.  ■ Orator V1.0 #1■ Mom looted LA & all I got was this lousy tagline.
  69.                                                                                
  70.                 
  71. PCRelay:ALMAC -> #1598 RelayNet (tm)
  72. 4.11             ALMAC PC Board BBS +44 (0)324-665371
  73.